home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 1196 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.1 KB  |  50 lines

  1. Path: overload.lbl.gov!news
  2. From: Mikhail Faiguenblat <mfaiguen>
  3. Newsgroups: comp.lang.c
  4. Subject: Locaton of an array?
  5. Date: 12 Jan 1996 02:59:32 GMT
  6. Organization: Lawrence Berkeley Laboratory, Berkeley CA
  7. Message-ID: <4d4iqk$hs3@overload.lbl.gov>
  8. NNTP-Posting-Host: issserv4.lbl.gov
  9. Mime-Version: 1.0
  10. Content-Type: text/plain; charset=us-ascii
  11. Content-Transfer-Encoding: 7bit
  12. X-Mailer: Mozilla 1.12 (X11; I; SunOS 5.4 sun4d)
  13. X-URL: news:comp.lang.c
  14.  
  15. I am sure this has been answered a million times by now, but could someody help
  16. me, please?
  17.  
  18. I have an array in my program, and I need to find out the absolute location in
  19. memory where this array is located. 
  20. I have tried to do it this way:
  21.  
  22. #include <stdio.h>
  23.  
  24. int main() {
  25.     char arr[10];
  26.     int addr;
  27.  
  28.     printf("sizeof(char *) = %d\n", sizeof(char *));
  29.     printf("sizeof(int) = %d\n", sizeof(int));
  30.  
  31.     addr = arr;
  32.  
  33.     printf("addr = %d\n", addr);
  34.  
  35.     return 0;
  36. }
  37.  
  38. And it did not work:
  39.  
  40. sizeof(char *) = 4
  41. sizeof(int) = 4
  42. addr = 2063810808
  43.  
  44. Obviously, the computer I run it on does not have 2Gb memory, so I must be
  45. doing something wrong.
  46. Can anybody help me?
  47.  
  48. Mikhail
  49.  
  50.